package fr.umlv.search;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultTreeCellRenderer;

import kiyut.ekspos.BrowserWindow;

import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.jdesktop.swingx.JXDatePicker;

import fr.umlv.authentication.SessionHandler;
import fr.umlv.cmis.listview.IconFactory;
import fr.umlv.cmis.treeview.CmiSObjectTreeModel;
import fr.umlv.metadata.Category;
import fr.umlv.metadata.CategoryHandlerModel;
import fr.umlv.utils.InfiniteProgressPanel;

// TODO: Auto-generated Javadoc
/**
 * The Class SearchWindow.
 */
public class SearchWindow extends JPanel{
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The bundle. */
	ResourceBundle bundle = ResourceBundle.getBundle("kiyut.ekspos.BrowserWindow",SessionHandler.getLocale());
	
	/** The search model. */
	private SearchModel searchModel;
	
	/** The search window result. */
	private SearchWindowResult searchWindowResult;
	
	/**
	 * Gets the search window result.
	 *
	 * @return the search window result
	 */
	public SearchWindowResult getSearchWindowResult() {
		return searchWindowResult;
	}

	/** The button group1. */
	private javax.swing.ButtonGroup buttonGroup1;
	
	/** The button group2. */
	private javax.swing.ButtonGroup buttonGroup2;
    
    /** The j button1. */
    private javax.swing.JButton jButton1;
    
    /** The j button2. */
    private javax.swing.JButton jButton2;
    
    /** The j button3. */
    private JButton jButton3;
    
    /** The j label1. */
    private javax.swing.JLabel jLabel1;
    
    /** The j label10. */
    private javax.swing.JLabel jLabel10;
    
    /** The j label11. */
    private javax.swing.JLabel jLabel11;
    
    /** The j label12. */
    private javax.swing.JLabel jLabel12;
    
    /** The j label13. */
    private javax.swing.JLabel jLabel13;
    
    /** The j label14. */
    private javax.swing.JLabel jLabel14;
    
    /** The j label15. */
    private javax.swing.JLabel jLabel15;
    
    /** The j label16. */
    private javax.swing.JLabel jLabel16;
    
    /** The j label17. */
    private javax.swing.JLabel jLabel17;
    
    /** The j label2. */
    private javax.swing.JLabel jLabel2;
    
    /** The j label3. */
    private javax.swing.JLabel jLabel3;
    
    /** The j label4. */
    private javax.swing.JLabel jLabel4;
    
    /** The j label5. */
    private javax.swing.JLabel jLabel5;
    
    /** The j label6. */
    private javax.swing.JLabel jLabel6;
    
    /** The j label8. */
    private javax.swing.JLabel jLabel8;
    
    /** The j label9. */
    private javax.swing.JLabel jLabel9;
    
    /** The j list1. */
    private javax.swing.JList jList1;
    
    /** The j panel1. */
    private javax.swing.JPanel jPanel1;
    
    /** The j panel2. */
    private javax.swing.JPanel jPanel2;
    
    /** The j panel3. */
    private javax.swing.JPanel jPanel3;
    
    /** The j radio button1. */
    private javax.swing.JRadioButton jRadioButton1;
    
    /** The j radio button2. */
    private javax.swing.JRadioButton jRadioButton2;
    
    /** The j radio button3. */
    private javax.swing.JRadioButton jRadioButton3;
    
    /** The j radio button4. */
    private javax.swing.JRadioButton jRadioButton4;
    
    /** The j radio button5. */
    private javax.swing.JRadioButton jRadioButton5;
    
    /** The j radio button6. */
    private javax.swing.JRadioButton jRadioButton6;
    
    /** The j scroll pane1. */
    private javax.swing.JScrollPane jScrollPane1;
    
    /** The j scroll pane2. */
    private javax.swing.JScrollPane jScrollPane2;
    
    /** The j scroll pane3. */
    private javax.swing.JScrollPane jScrollPane3;
    
    /** The j tabbed pane1. */
    private javax.swing.JTabbedPane jTabbedPane1;
    
    /** The j text field1. */
    private javax.swing.JTextField jTextField1;
    
    /** The j text field2. */
    private javax.swing.JTextField jTextField2;
    
    /** The j text area3. */
    private JTextArea jTextArea3;
    
    /** The j text field4. */
    private javax.swing.JTextField jTextField4;
    
    /** The j date5. */
    private JXDatePicker jDate5;
    
    /** The j date6. */
    private JXDatePicker jDate6;
    
    /** The j date7. */
    private JXDatePicker jDate7;
    
    /** The j date8. */
    private JXDatePicker jDate8;
    
    /** The j tree1. */
    private javax.swing.JTree jTree1;
    
    /** The j tree2. */
    private javax.swing.JTree jTree2;
    
    /** The main panel. */
    private javax.swing.JPanel mainPanel;
    
    /** The progress bar. */
    private javax.swing.JProgressBar progressBar;
    
    /** The status animation label. */
    private javax.swing.JLabel statusAnimationLabel;
    
    /** The status message label. */
    private javax.swing.JLabel statusMessageLabel;
    
    /** The status panel. */
    private javax.swing.JPanel statusPanel;
    // End of variables declaration
	
	/** The cmis object tree model. */
    private CmiSObjectTreeModel cmisObjectTreeModel;
	
	/** The parent. */
	private final BrowserWindow parent;
    
    
	
	/**
	 * Instantiates a new search window.
	 *
	 * @param cmiSObjectTreeModel the cmi s object tree model
	 * @param parent the parent
	 */
	public SearchWindow(CmiSObjectTreeModel cmiSObjectTreeModel, final BrowserWindow parent){
		this.cmisObjectTreeModel=cmiSObjectTreeModel;
		this.parent=parent;
		this.setLayout(new BorderLayout());
		// Put the GUI in front of window
	    //this.setAlwaysOnTop(true);
	    //this.setLocationRelativeTo(this.getParent());
	    //this.setTitle(bundle.getString("search_title"));
	    //this.setIconImage(Toolkit.getDefaultToolkit().createImage(Application.class.getResource("/kiyut/ekspos/zoom.png")));
		mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTree2 = new javax.swing.JTree();
        jButton1 = new javax.swing.JButton();
        jButton3 = new JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextArea3 = new javax.swing.JTextArea(4,5);
        jLabel10 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        //jDate5 = new javax.swing.JFormattedTextField(new MaskFormatter("##/##/####"));
        //jDate6 = new javax.swing.JFormattedTextField(new MaskFormatter("##/##/####"));
        //jDate7 = new javax.swing.JFormattedTextField(new MaskFormatter("##/##/####"));
        //jDate8 = new javax.swing.JFormattedTextField(new MaskFormatter("##/##/####"));
        jDate5 = new JXDatePicker();
        jDate6 = new JXDatePicker();
        jDate7 = new JXDatePicker();
        jDate8 = new JXDatePicker();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();  
        jButton2 = new javax.swing.JButton();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N

        jLabel1.setText(bundle.getString("search_sentence")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(bundle.getString("search_verb")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        //jTextField1.setText(bundle.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N
        jTextField1.setColumns(20);

        jLabel3.setText(bundle.getString("search_show_results_for")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText(bundle.getString("search_all_elements")); // NOI18N
        jRadioButton1.setName("jRadioButton1"); // NOI18N
        jRadioButton1.setSelected(true);

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText(bundle.getString("search_only_files")); // NOI18N
        jRadioButton2.setName("jRadioButton2"); // NOI18N

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText(bundle.getString("search_content_and_files")); // NOI18N
        jRadioButton3.setName("jRadioButton3"); // NOI18N

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setText(bundle.getString("search_only_spaces")); // NOI18N
        jRadioButton4.setName("jRadioButton4"); // NOI18N

        jLabel4.setText(bundle.getString("search_advanced_parameters")); // NOI18N
        jLabel4.setFont(new Font("",Font.BOLD,12));
        jLabel4.setName("jLabel4"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel5.setText(bundle.getString("search_particular_space")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        buttonGroup2.add(jRadioButton5);
        jRadioButton5.setText(bundle.getString("search_all_spaces")); // NOI18N
        jRadioButton5.setName("jRadioButton5"); // NOI18N
        jRadioButton5.setSelected(true);
        jRadioButton5.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				if(jRadioButton6.isSelected()){
					jTree1.setEnabled(true);
				}
				else{
					jTree1.setEnabled(false);
				}
			}
		});

        buttonGroup2.add(jRadioButton6);
        jRadioButton6.setText(bundle.getString("search_particular_space")); // NOI18N
        jRadioButton6.setName("jRadioButton6"); // NOI18N
        jRadioButton6.addActionListener(new ActionListener() {
			
	
			public void actionPerformed(ActionEvent e) {
				if(jRadioButton6.isSelected()){
					jTree1.setEnabled(true);
					
				}
				else{
					jTree1.setEnabled(false);
				}
			}
		});

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTree1.setName("jTree1"); // NOI18N
        jTree1.setEnabled(false);
        jTree1.setModel(this.cmisObjectTreeModel);
        
		
		jTree1.setCellRenderer(new DefaultTreeCellRenderer(){

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			
			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
				super.getTreeCellRendererComponent(tree,value,selected,expanded,leaf,row,hasFocus);
				
				ImageIcon icon = IconFactory.getFolderIcon(16);
				setIcon(icon);
			    if (leaf == true) {
		            setLeafIcon(icon);
		        } else {
		            setClosedIcon(icon);
		            setOpenIcon(icon);
		        }
			    
			    return this;
				
			}	
		});
		
        jScrollPane1.setViewportView(jTree1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGap(70,70,70)
                        .addComponent(jLabel5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(98, 98, 98)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton6)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(261, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(bundle.getString("search_emplacement"), jPanel1); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel6.setText(bundle.getString("search_available_categories")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTree2.setName("jTree2"); // NOI18N
        jTree2.setRootVisible(false);
        jScrollPane2.setViewportView(jTree2);
        
        jTree2.setModel(new CategoryHandlerModel());
        
        jTree2.setCellRenderer(new DefaultTreeCellRenderer(){

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			
			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
				super.getTreeCellRendererComponent(tree,value,selected,expanded,leaf,row,hasFocus);
				
				ImageIcon icon = IconFactory.getFolderIcon(16);
				setIcon(icon);
			    if (leaf == true) {
		            setLeafIcon(icon);
		        } else {
		            setClosedIcon(icon);
		            setOpenIcon(icon);
		        }
			    
			    return this;		
			}	
		});

       

        jScrollPane3.setName("jScrollPane3"); // NOI18N
       
        final DefaultListModel categoriesList = new DefaultListModel();
        

        jList1.setModel(categoriesList);
        
        
        jList1.setName("jList1"); // NOI18N
        jScrollPane3.setViewportView(jList1);
        
        
        jButton3.setText(">>"); // NOI18N
        jButton3.setName("jButton1"); // NOI18N
        jButton3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				categoriesList.addElement(jTree2.getSelectionPath().getLastPathComponent());
			}
		});
        
        jButton1.setText("<<");
        jButton1.setName("jButton3");
        jButton1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(jList1.getSelectedIndex()>=0){
					categoriesList.remove(jList1.getSelectedIndex());
				}		
			}
		});
        
        
        
        jLabel17.setText(bundle.getString("search_chosen_categories")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(67, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(86, 86, 86)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jButton1))
                .addGap(66, 66, 66)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
                .addComponent(jLabel17)
                .addGap(151, 151, 151))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel17))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(100, 100, 100)
                                        .addComponent(jButton1)))))
                .addContainerGap(26, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(146, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addGap(129, 129, 129))
        );

        jTabbedPane1.addTab(bundle.getString("search_category"), jPanel2); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N


        jLabel8.setText(bundle.getString("search_title_constraints")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTextField2.setName("jTextField2"); // NOI18N

        jLabel9.setText(bundle.getString("search_description")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTextArea3.setName("jTextField3"); // NOI18N
        jTextArea3.setBorder(BorderFactory.createEtchedBorder());

        jLabel10.setText(bundle.getString("search_author")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jTextField4.setName("jTextField4"); // NOI18N

        jLabel11.setText(bundle.getString("search_modification_date")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText(bundle.getString("search_from")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jDate5.setName("jTextField5"); // NOI18N
        jDate5.setFormats(new SimpleDateFormat("dd/MM/yy"));
        jDate5.setPreferredSize(new Dimension(70,20));
        jDate5.setMinimumSize(new Dimension(70,20));
        jDate5.setMaximumSize(new Dimension(70,20));
        
        jLabel13.setText(bundle.getString("search_to")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jDate6.setName("jTextField6"); // NOI18N
        jDate6.setFormats(new SimpleDateFormat("dd/MM/yy"));
        jDate6.setPreferredSize(new Dimension(70,20));
        jDate6.setMinimumSize(new Dimension(70,20));
        jDate6.setMaximumSize(new Dimension(70,20));
        
        jLabel14.setText(bundle.getString("search_creation_date")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(bundle.getString("search_from")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jDate7.setName("jTextField7"); // NOI18N
        jDate7.setFormats(new SimpleDateFormat("dd/MM/yy"));
        jDate7.setPreferredSize(new Dimension(70,20));
        jDate7.setMinimumSize(new Dimension(70,20));
        jDate7.setMaximumSize(new Dimension(70,20));

        jLabel16.setText(bundle.getString("search_to")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jDate8.setName("jTextField8"); // NOI18N
        jDate8.setFormats(new SimpleDateFormat("dd/MM/yy"));
        jDate8.setPreferredSize(new Dimension(70,20));
        jDate8.setMinimumSize(new Dimension(70,20));
        jDate8.setMaximumSize(new Dimension(70,20));
        

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                //.addGap(23, 23, 23)
            	.addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel14))
                //.addGap(54, 54, 54)
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(12, 12, 12)
                        .addComponent(jDate7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(jLabel16)
                        .addGap(12, 12, 12)
                        .addComponent(jDate8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(12, 12, 12)
                        .addComponent(jDate5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(jLabel13)
                        .addGap(12, 12, 12)
                        .addComponent(jDate6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField4, 200, 200, 200)
                        .addComponent(jTextArea3, 200, 200, 200)
                        .addComponent(jTextField2, 200, 200, 200)
                        ))
                .addGap(233, 233, 233))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    )
                //.addGap(28, 28, 28)
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextArea3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jDate5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jDate6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addComponent(jDate7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(jDate8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(bundle.getString("search_advanced_parameters"), jPanel3); // NOI18N

        jButton2.setText(bundle.getString("search_button")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        final SearchWindow searchWindow = this;
        final InfiniteProgressPanel glassPane = new InfiniteProgressPanel();
        
        parent.setGlassPane(glassPane);
        jButton2.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				jButton2.setEnabled(false);
				glassPane.start();
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						Thread performer = new Thread(new Runnable() {
							public void run() {
								//loading2();

								HashMap<String, String> propertiesSearch = new HashMap<String, String>();
								propertiesSearch.put("filename", jTextField1.getText());
								propertiesSearch.put("button_all_elements", new Boolean(jRadioButton1.isSelected()).toString());
								propertiesSearch.put("button_file_only", new Boolean(jRadioButton2.isSelected()).toString());
								propertiesSearch.put("button_file_and_contents", new Boolean(jRadioButton3.isSelected()).toString());
								propertiesSearch.put("button_space_only", new Boolean(jRadioButton4.isSelected()).toString());
								propertiesSearch.put("button_all_spaces", new Boolean(jRadioButton5.isSelected()).toString());
								propertiesSearch.put("button_specific_space", new Boolean(jRadioButton6.isSelected()).toString());
								
								
								String strTree1;
								if(jTree1.getSelectionPath()!=null){
									strTree1 = "/" + jTree1.getSelectionPath().toString();
								}
								else{
									strTree1 = "";
								}
								
								
				        		strTree1 = strTree1.replace(", ","/");
				        		strTree1 = strTree1.replace("[", "");
				        		strTree1 = strTree1.replace("]", "");
								propertiesSearch.put("tree_specific_space", strTree1);
								String strjlist1 = "";
								// recuperer tous les elements d une liste
								for(int i=0;i<jList1.getModel().getSize();++i){
									Category tmp = (Category) jList1.getModel().getElementAt(i);
									strjlist1 += tmp.getPath() + ", ";
								}
								
								Date date_modification_from = jDate5.getDate();
								Date date_modification_to = jDate6.getDate();
								Date date_creation_from = jDate7.getDate();
								Date date_creation_to = jDate8.getDate();
								
								DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

								
								String modification_from = "  /  /    ";
								String modification_to = "  /  /    ";
								String creation_from = "  /  /    ";
								String creation_to = "  /  /    ";
								
								
								
								
								if(date_modification_from != null){
									modification_from = dateFormat.format(date_modification_from);
								}
								
								if(date_modification_to != null){
									modification_to = dateFormat.format(date_modification_to);
								}
								
								if(date_creation_from != null){
									creation_from = dateFormat.format(date_creation_from);
								}
								
								if(date_creation_to != null){
									creation_to = dateFormat.format(date_creation_to);
								}
								
								
								propertiesSearch.put("list_categories", strjlist1);
								propertiesSearch.put("title", jTextField2.getText());
								propertiesSearch.put("description", jTextArea3.getText());
								propertiesSearch.put("author", jTextField4.getText());
								propertiesSearch.put("modification_from", modification_from);
								propertiesSearch.put("modification_to", modification_to);
								propertiesSearch.put("creation_from", creation_from);
								propertiesSearch.put("creation_to", creation_to);
								//JDialog dialog = new JDialog();
								
								try{
									searchModel = new SearchModel(false,1,propertiesSearch);
									searchWindow.displaySearchResults();
									glassPane.interrupt();
								}catch(CmisRuntimeException exp){
									//waitFrame.stopFrame();
									//dialog.dispose();
									jButton2.setEnabled(true);
									glassPane.interrupt();
									JOptionPane.showMessageDialog(parent, bundle.getString("ErrorIntern.text"),
											"Error", JOptionPane.ERROR_MESSAGE);
								}catch(CmisNoResultsException exp){
									//waitFrame.stopFrame();
									//dialog.dispose();
									jButton2.setEnabled(true);
									glassPane.interrupt();
									JOptionPane.showMessageDialog(parent, bundle.getString("search_no_results"),
											bundle.getString("search_title"), JOptionPane.INFORMATION_MESSAGE);
								}catch(NoCritersException exp){
									jButton2.setEnabled(true);
									glassPane.interrupt();
									JOptionPane.showMessageDialog(parent, bundle.getString("search_no_criters"),
											bundle.getString("search_title"), JOptionPane.INFORMATION_MESSAGE);
								}catch (MalformedCritersException e) {
									jButton2.setEnabled(true);
									glassPane.interrupt();
									JOptionPane.showMessageDialog(parent, bundle.getString("search_wrong_criters"),
											bundle.getString("search_title"), JOptionPane.ERROR_MESSAGE);
								}
								finally{
									jButton2.setEnabled(true);
								}
							}
						}, "Performer");
						performer.start();
					}
				});
				

			}
		});

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        //.addGap(100, 100, 100)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        	.addComponent(jLabel1)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        //.addGap(80, 80, 80)
                    	.addGap(30, 30, 30)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2))
                        .addGap(58, 58, 58)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton4)
                            .addComponent(jRadioButton3)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        //.addGap(100, 100, 100)
                        .addComponent(jLabel4))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        //.addGap(100,100,100)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE))))
                //.addContainerGap(63, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                //.addContainerGap(100, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(10, 10, 10))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGap(20,20,20)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton4))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(jButton2)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 512, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11))
        );
        
        
        this.add(mainPanel);
        int sizeXPanel = 580;
        int sizeYPanel = 600;
        mainPanel.setSize(sizeXPanel, sizeYPanel);
        mainPanel.setPreferredSize(new Dimension(sizeXPanel,sizeYPanel));
        mainPanel.setMinimumSize(new Dimension(sizeXPanel,sizeYPanel));
        mainPanel.setMaximumSize(new Dimension(sizeXPanel,sizeYPanel));
        this.setPreferredSize(new Dimension(sizeXPanel, sizeYPanel));
        //this.add(new SearchWindowResult());
        this.setVisible(true);
	}

	/**
	 * Display search results.
	 */
	public void displaySearchResults(){
		mainPanel.setVisible(false);
		if(this.searchWindowResult!=null){
			this.remove(this.searchWindowResult);
		}
		this.searchWindowResult = new SearchWindowResult(searchModel, mainPanel, parent);
		this.add(this.searchWindowResult);
		this.revalidate();
		this.repaint();
	}
	
	/**
	 * Sets the search model.
	 *
	 * @param searchModel the search model
	 */
	public void SetSearchModel(SearchModel searchModel){
		this.searchModel = searchModel;
	}
}
